package soundwave.com.demo.adpater;

import android.content.Context;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;

import soundwave.com.demo.R;
import soundwave.com.demo.test.Headlinecontent_test;

/**
 * Created by xu on 2017/4/29.
 */

public class Headlines_adapert extends ArrayAdapter<Headlinecontent_test> {
    private ArrayList<Headlinecontent_test> headlines;
    private int layoutid;
    private LayoutInflater inflater;
    private Context context;

    public Headlines_adapert(Context context, int resource,ArrayList<Headlinecontent_test> headlines) {
        super(context, resource,headlines);
        this.layoutid=resource;
        this.headlines=headlines;
        this.context=context;
    }

    @NonNull
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view=convertView;
        if (view==null){
            inflater=LayoutInflater.from(context);
            view=inflater.inflate(layoutid,null);
        }
        Headlinecontent_test headlinecontent_test=getItem(position);
        ImageView headlines_img= (ImageView) view.findViewById(R.id.headlines_img);
        TextView headlines_title= (TextView) view.findViewById(R.id.headlines_title);
        TextView headlines_news= (TextView) view.findViewById(R.id.headlines_news);
        TextView headlines_time= (TextView) view.findViewById(R.id.headlines_time);

        headlines_img.setImageResource(headlinecontent_test.getHeadlines_img());
        headlines_title.setText(headlinecontent_test.getHeadlines_title());
        headlines_news.setText(headlinecontent_test.getHeadlines_news());
        headlines_time.setText(headlinecontent_test.getHeadlines_time());


        return view;
    }

    @Override
    public int getCount() {
        return headlines.size();
    }
}
